package cn.lsngo.manager;

import android.text.TextUtils;

/**
 * @Title :
 * @date : 2021/10/27 18:15
 */
public class ArithUtil {
    public static double parseStr2Double(String str) {
        double v = 0;
        if (str == null || TextUtils.isEmpty(str)) {
            return v;
        }

        try {
            v = Double.parseDouble(str);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            v = 0;
        }
        return v;
    }

    public static double sub(String start, String end) {
        double mStart = parseStr2Double(start);
        double mEnd = parseStr2Double(end);
        double v = mEnd - mStart;
        return v;
    }

    public static double remain2dot(double v) {
        String s = "0";
        try {
             s = String.format("%.2f", v);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return parseStr2Double(s);
    }
}
